package com.xuetang9.t9.xinhuaxia.mappers;

import com.xuetang9.t9.xinhuaxia.beans.Goods;
import com.xuetang9.t9.xinhuaxia.beans.Orderlist;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface OrderlistMapper extends Mapper<Orderlist> {
    @Select("select * from orderlist")
    @Results(id = "orderList", value = {
            @Result(property = "userOrderlist",column = "o_orderId",
                    one =@One(select = "com.xuetang9.t9.xinhuaxia.mappers.UserOrderlistMapper.queryById")),

            @Result(property = "goods",column = "o_goodsId",
                    one = @One(select = "com.xuetang9.t9.xinhuaxia.mappers.GoodsMapper.queryById")),

            @Result(property = "oId",column = "o_id"),
            @Result(property = "oOrderid",column = "o_orderId"),
            @Result(property = "oGoodsid",column = "o_goodsId"),
            @Result(property = "oCount",column = "o_count")
    })
    List<Orderlist> queryAll();

    @Select("select * from orderlist where o_id = #{id} order by o_id desc")
    @ResultMap("orderList")
    Orderlist queryById(@Param("id") Long id);

    /*用户订单查询*/
    @Select("select * from orderlist where o_orderId = #{id} order by o_id desc")
    @Results(id = "userOrderList", value = {
            @Result(property = "goods",column = "o_goodsId",
                    one = @One(select = "com.xuetang9.t9.xinhuaxia.mappers.GoodsMapper.queryById")),
            @Result(property = "oId",column = "o_id"),
            @Result(property = "oOrderid",column = "o_orderId"),
            @Result(property = "oGoodsid",column = "o_goodsId"),
            @Result(property = "oCount",column = "o_count")
    })
    List<Orderlist> queryByOrderId(@Param("id") Long id);
}